<?php
/**
 * XSLT-Plugin: Renders docbook blocks transforming them to XHTML
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Juergen A. Lamers <jaloma.ac@googlemail.com>
 */

if (!defined('DOKU_INC'))define('DOKU_INC', realpath(dirname( __FILE__ ).'/../../../../').'/');
if (!defined('DOKU_PLUGIN'))define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
//require_once (DOKU_PLUGIN.'xsltproc/syntax.php');
require_once (DOKU_PLUGIN.'xsltproc/syntax/ixsltproc.php');
require_once (DOKU_PLUGIN.'xsltproc/xslt_helper.php');

class syntax_plugin_docbook2 extends syntax_plugin_xsltproc_ixsltproc
{

    /**
     * General Info
     *
     * Returns an associative array with some info about the plugin
     */
    function getInfo()
    {
        return array (
        'author'=>'Juergen A.Lamers',
        'email'=>'jaloma.ac@gogglemail.com',
        'date'=>'2009-03-09',
        'name'=>'docbook2 Plugin',
        'desc'=>'Allows docbook markup and renders it as XHTML',
        'url'=>'http://dokuwiki.ich-bin-am-wandern-gewesen.de/plugin:xsltsuite',
        );
    }

    /**
     * Connect pattern to lexer
     */
/*	
    function connectTo($mode)
    {
        $this->Lexer->addEntryPattern('<'.$this->getTagName().'>', $mode, $this->connectName());
    }

    function postConnect()
    {
        $this->Lexer->addExitPattern('</'.$this->getTagName().'>', $this->connectName());
    }
*/
    function getTagName()
    {
        return "docbook2";
    }

	function connectName() {
		return "plugin_".$this->getTagName();
	}

    /**
     * Applies the stylesheet defined in settings to the docbook block to get a XHTML document,
     * gets body element's children removing the xmlns declaration for XHTML and returns
     * the resulting string.
     *
     * Uses xsltproc program executed in an external shell to do the XSL transformations.
     * It also creates some cache files with the docbook block and the XHTML document
     * made when applying the XSLT to the docbook.
     *
     * @param   $giadocbookBlock   The docbook block to be transformed
     * @return  string          The transformed XHTML code
     */
    function transformIXsltProcInXhtml($giadocbookBlock)
    {
        global $conf;

        $xslDocument = $this->getConf('giaDocbookDataFile_xslfile');
        $xslDir = realpath(dirname( __FILE__ ).'/styles');
		$docbookres = $this->callTransform($giadocbookBlock, $xslDocument, $xslDir);
		/* Strip <?xml <xhtml and <body Tags from the result */
		$xslDocument = "xHtmlCleaner.xsl";
		return $this->callTransform($docbookres, $xslDocument, $xslDir);
    }

}
